package com.silence.gankio.activity

import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.widget.TableLayout
import com.silence.gankio.R
import com.silence.gankio.mvvm.BaseActivity
import com.silence.gankio.mvvm.viewModel.BaseViewModel
import com.silence.gankio.widget.ToolBarCommView
import com.silence.gankio.widget.media.AndroidMediaController
import com.silence.gankio.widget.media.IRenderView
import kotlinx.android.synthetic.main.activity_ijk_player.*
import kotlinx.android.synthetic.main.activity_ijk_player.view.*
import tv.danmaku.ijk.media.player.IjkMediaPlayer


class IjkPlayerActivity : BaseActivity<BaseViewModel>() {
    override fun getModelClass() = null

    override fun getActivityContent() = R.layout.activity_ijk_player


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val title = intent.getStringExtra("title")
        val url = intent.getStringExtra("url")
        val imageUrl = intent.getStringExtra("imageUrl")

        setToolBarTitle(title)
        setBackArrow()

//        IjkMediaPlayer.loadLibrariesOnce(null)
//        IjkMediaPlayer.native_profileBegin("libijkplayer.so")
        player_view.setHudView(TableLayout(this))
        val controller = AndroidMediaController(this, true)
        player_view.setMediaController(controller)
        player_view.setVideoURI(Uri.parse(url))
        player_view.start()

        //	以下为配置接口，选择需要的调用
//        Glide.with(this).load(imageUrl).fitCenter().into(player_view.mPlayerThumb)	// 显示界面图
//        player_view.init()
//            .setTitle(title)
//            .setSkipTip(1000*60*1)
//            .enableOrientation()
//            .alwaysFullScreen()
//            .setVideoPath(url)
//            .setMediaQuality(IjkPlayerView.MEDIA_QUALITY_HIGH)
//            .start()
    }


    override fun onResume() {
        super.onResume()
        player_view.resume()
    }

    override fun onPause() {
        super.onPause()
        player_view.pause()
    }

    override fun onDestroy() {
        super.onDestroy()
//        player_view.dest()
    }

    override fun onConfigurationChanged(newConfig: Configuration?) {
        super.onConfigurationChanged(newConfig)
//        player_view.configurationChanged(newConfig)
    }

//    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
//        if (player_view.handleVolumeKey(keyCode)) {
//            return true
//        }
//        return super.onKeyDown(keyCode, event)
//    }

//    override fun onBackPressed() {
//        if (player_view.onBackPressed()) {
//            return
//        }
//        super.onBackPressed()
//    }
}
